-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace outputstream with writeroutputstream #234
Conversation
transfuse/src/test/java/org/androidtransfuse/gen/FilerResourceWriterTest.java
Show resolved
Hide resolved
OutputStream os = resource.openOutputStream(); | ||
openStreams.add(os); | ||
|
||
OutputStream os = new WriterOutputStream(resource.openWriter()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor is depreciated, we should define a charset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to
OutputStream os = new WriterOutputStream(sourceFile.openWriter(), "UTF-8");
is it okay to use UTF-8 ?
for (OutputStream openStream : openStreams) { | ||
openStream.flush(); | ||
openStream.close(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not keep these calls? It seems like they would be necessary because we'll be dealing with a buffer with WriterOutputStream
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is causing this error
Caused by: java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen (StreamEncoder.java:45)
at sun.nio.cs.StreamEncoder.flush (StreamEncoder.java:140)
at java.io.OutputStreamWriter.flush (OutputStreamWriter.java:229)
at java.io.FilterWriter.flush (FilterWriter.java:100)
at org.androidtransfuse.util.apache.commons.WriterOutputStream.flush (WriterOutputStream.java:83)
at org.androidtransfuse.gen.FilerSourceCodeWriter.close (FilerSourceCodeWriter.java:65)
at com.sun.codemodel.JCodeModel.build (JCodeModel.java:312)
Seems it already closed by the WriterOutputStream
public void close() throws IOException {
this.processInput(true);
this.flushOutput();
this.writer.close();
}
Do you have other clue why it causing error ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I bet codemodel is already closing the output stream and since it's closed flush throws an error. You can outright get rid of the flush call instead of just commenting it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it seems already flush and also closed from the log, also looking from the flamegraph.
|
||
codeWriter.close(); | ||
verify(mockOutputStream).flush(); | ||
verify(mockOutputStream).close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I'd really like to keep these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now it seems this test not doing anything right ? do you have idea what we should test, or should we remove it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would breing everything back except for verify(mockOutputStream).flush();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just modify the test, and add spy there when creating codeWriter object. Also, i put a new method so we can mock this part
doReturn(mockOutputStream).when(codeWriter).getWriterOutputStream(mockWriter);
please let me know if you have better approach on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, great, I think that works.
@@ -53,8 +53,9 @@ | |||
<dependency> | |||
<groupId>commons-io</groupId> | |||
<artifactId>commons-io</artifactId> | |||
<version>2.4</version> | |||
<version>2.5</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍... there are a few more commons-io used in testing, could you upgrade those as well in this pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -49,10 +50,8 @@ public OutputStream openBinary(JPackage jPackage, String fileName) throws IOExce | |||
//generate a source file based on package and fileName | |||
String qualified = toQualifiedClassName(jPackage, fileName); | |||
JavaFileObject sourceFile = filer.createSourceFile(qualified, originating.getOriginatingElements(qualified)); | |||
|
|||
OutputStream os = sourceFile.openOutputStream(); | |||
OutputStream os = new WriterOutputStream(sourceFile.openWriter(), "UTF-8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass in StandardCharsets.UTF_8
instead of the string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, i just replace it
@@ -63,7 +62,7 @@ private String toQualifiedClassName(JPackage pkg, String fileName) { | |||
@Override | |||
public void close() throws IOException { | |||
for (OutputStream openStream : openStreams) { | |||
openStream.flush(); | |||
// openStream.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go ahead and get rid of anything not used. Since we're using utf-8, the checkIbmJdkWithBrokenUTF16
will never execute, and most of the constructors can be combined into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, i just removed it and combine the constructor.
…fuse-support, remove unused code on writeroutputstream
@@ -0,0 +1,88 @@ | |||
package org.androidtransfuse.util.apache.commons; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd stick this in org.androidtransfuse.gen
next to FilerSourceCodeWriter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, just moved next to FilerSourceCodeWriter
openStreams.add(os); | ||
|
||
return os; | ||
} | ||
|
||
public OutputStream getWriterOutputStream(Writer writer) { | ||
return new WriterOutputStream(writer, StandardCharsets.UTF_8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johncarl81 using StandardCharsets.UTF_8 this actually red on my editor. it required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, too big of a chance for this... maybe just define the string as a constant in this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes i changed it to Charset.forName("UTF-8") it should be equals to it.
* | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Hi do you still have any further concern about this PR ? thank you |
Nope, I'm ready to merge. I just haven't had a moment to focus on this. Do you need this and parceler updated and pushed out to maven central? |
thanks @johncarl81, yes would be nice if i can try it on stable version. But actually not that urgent, i guess it is up to you. |
Issue:
#233